package com.gp.study.mybatis.session;

import java.sql.SQLException;

import com.gp.study.mybatis.executor.Executor;

public class DefaultSqlSession implements SqlSession {

	private Configuration configuration;
	private Executor executor;
	
	public DefaultSqlSession(Configuration configuration) {
		this.configuration = configuration;
		this.executor = configuration.newExecutor();
	}

	@Override
	public <T> T selectOne(String statementId, Object[] parameter) throws SQLException {
		//根据statementid 获取 sql
		MapperMethodMeta sqlMeta=configuration.getMapperStateMent(statementId);
		return executor.query(sqlMeta.getSql(), parameter,sqlMeta.getType());
	}

//	@Override
//	public <T> List<T> selectMany(String statementId, Object param) {
//		// TODO Auto-generated method stub
//		return null;
//	}

	@Override
	public <T> T getMapper(Class<T> type) {
		return (T)configuration.getMapper(type,this);
	}

	@Override
	public Configuration getConfiguration() {
		return configuration;
	}

	public Executor getExecutor() {
		return executor;
	}


}
